home *** CD-ROM | disk | FTP | other *** search
- /*
- Exceptions.h
-
- C++ style exception handling.
-
- Part of PatchWorks, the Extension Development Framework.
-
- by Mouse Herrell & Patrick Beard.
-
- Permission is granted to use this source code for any purpose, as long
- as the copyright notice is maintained.
-
- © 1992 Berkeley Systems, Inc.
- */
-
- #pragma once
-
- #ifndef __EXCEPTIONS__
- #define __EXCEPTIONS__
-
- #include <setjmp.h>
-
- struct ExceptionFrame {
- jmp_buf frame;
- struct ExceptionFrame* next;
- };
-
- typedef struct ExceptionFrame ExceptionFrame;
-
- extern int theException;
- extern ExceptionFrame* theFrame;
-
- #define throw(value) longjmp(theFrame->frame, value)
-
- #define try \
- { ExceptionFrame exception; \
- exception.next = theFrame; \
- theFrame = &exception; \
- if (!(theException = setjmp(theFrame->frame))) { \
-
- #define catch \
- } \
- theFrame = theFrame->next; \
- } \
- for (; theException != 0; theException = 0)
-
- // convenience macros.
-
- #define FailNil(p) do { if (!p) throw(memFullErr); } while (0)
- #define FailErr(e) do { if (e != noErr) throw(e); } while (0)
-
- #endif
-